package com.kyin.satoken.service;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.kyin.satoken.common.R;
import com.kyin.satoken.exception.GlobalException;
import com.kyin.satoken.utils.CryptoUtil;
import org.springframework.stereotype.Service;
import org.ssssssss.magicapi.core.service.MagicAPIService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yin.kai
 * @ClassName MagicApiService
 * @description: 类描述
 * @date 2025/9/22 15:04
 * @version: 1.0
 */
@Service
public class MagicApiService {


    private static final String MAGIC_URL_KEY = "reqUrl";
    @Resource
    private MagicAPIService magicAPIService;

    public R getRequest(Map<String, Object> params) throws Exception {

        String url = MapUtil.getStr(params, MAGIC_URL_KEY);
        Map<String,Object> result= magicAPIService.execute("GET", url, params);
        return R.ok(result);
    }

    public R postRequest(Map<String, Object> params) throws Exception{
        Map<String, Object> body = new HashMap<>();
        String url = MapUtil.getStr(params, MAGIC_URL_KEY);
        body.put("body", params);
        Map<String,Object> result= magicAPIService.execute("POST", url, body);
        return R.ok(result);
    }

}
